﻿using SUNRPA.CONTROLS.IMPL.domain;
using SUNRPA.CONTROLS.IMPL.domain.constant;
using SUNRPA.CONTROLS.IMPL.domain.flowItemParam;
using SUNRPA.CONTROLS.IMPL.domain.flowRunningVar;
using SUNRPA.CONTROLS.IMPL.util;
using System.Collections.Concurrent;
using System.Text;

namespace SUNRPA.CONTROLS.IMPL.controls {
    public class SetWindowStatusNAction: BaseControlActions {
        public override int Execute(int currentIndex, FlowItem item, ConcurrentDictionary<string, ConcurrentDictionary<string, RPAVariableDefineWrapper>> globleData, List<FlowItem> flowItems) {
            SetWindowStatusNParam? param = item.ControlParam as SetWindowStatusNParam;
            IntPtr currentWin = User32Utils.GetForegroundWindow();
            StringBuilder sb = new StringBuilder();
            User32Utils.GetWindowText(currentWin, sb, 256);
            switch(param.WinStatus) {
                //最大
                case 0:
                    User32Utils.ShowWindow(currentWin, ShowMessageEnum.SW_SHOWMAXIMIZED);
                    break;
                //最小
                case 1:
                    User32Utils.ShowWindow(currentWin, ShowMessageEnum.SW_MINIMIZE);
                    break;
                case 2:
                    User32Utils.SendMessage(currentWin, (int)WinMessages.WM_CLOSE, 0, 0);
                    break;
            }
            return currentIndex;
        }
    }
}
